﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace MethodWorx.CMS.Plugins
{
    [Serializable]
    public class ImageAssetPickerPropertyDetails : ICustomPropertyDetails
    {
        public string Title { get; set; }
        public string Path { get; set; }
        public int? Width { get; set; }
        public int? Height { get; set; }
        public string AlternateText { get; set; }

        public void CopyValueFrom(ICustomPropertyDetails from)
        {
            var property = from as ImageAssetPickerPropertyDetails;
            if(property != null)
            {
                this.Title = property.Title;
                this.Path = property.Path;
                this.Width = property.Width;
                this.Height = property.Height;
                this.AlternateText = property.AlternateText;
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<img ");
            sb.AppendFormat("src=\"{0}\" ", this.Path.TrimStart('/'));
            if(!string.IsNullOrEmpty(this.Title))
                sb.AppendFormat("title=\"{0}\" ", this.Title);

            if (!string.IsNullOrEmpty(this.AlternateText))
                sb.AppendFormat("alt=\"{0}\" ", this.AlternateText);

            if (!string.IsNullOrEmpty(this.Width.ToString()))
                sb.AppendFormat("width=\"{0}\" ", this.Width);

            if (!string.IsNullOrEmpty(this.Height.ToString()))
                sb.AppendFormat("height=\"{0}\" ", this.Height);

            sb.AppendFormat("/>");

            return sb.ToString();
        }

        #region ICustomPropertyDetails Members


        public void Parse(string input)
        {
            this.Path = input;
        }

        #endregion
        public object Clone()
        {
            return this.MemberwiseClone();
        }


        public bool IsNull()
        {
            return string.IsNullOrEmpty(this.Path);
        }

        public bool IsEmpty()
        {
            return string.IsNullOrEmpty(this.Path);
        }

    }
}
